{php include wl_template('common/header');}
<style>
	.prstyle{color: orangered;}
</style>
<ul class="nav nav-tabs">
	<li {if $status == 0 || empty($status)}class="active"{/if}><a href="{php echo wl_filter_url('status:0');}">商品全部{if $status10}<span class="label label-warning pull-right">{$status10}</span>{/if}</a></li>
	<li {if $status == 1}class="active"{/if}><a href="{php echo wl_filter_url('status:1');}">待开始{if $status1}<span class="label label-warning pull-right">{$status1}</span>{/if}</a></li>
	<li {if $status == 2}class="active"{/if}><a href="{php echo wl_filter_url('status:2');}">销售中{if $status2}<span class="label label-warning pull-right">{$status2}</span>{/if}</a></li>
	<li {if $status == 3}class="active"{/if}><a href="{php echo wl_filter_url('status:3');}">已结束{if $status3}<span class="label label-warning pull-right">{$status3}</span>{/if}</a></li>
	<li {if $status == 4}class="active"{/if}><a href="{php echo wl_filter_url('status:4');}">已下架{if $status4}<span class="label label-warning pull-right">{$status4}</span>{/if}</a></li>
	<li {if $status == 5}class="active"{/if}><a href="{php echo wl_filter_url('status:5');}">待审核{if $status5}<span class="label label-warning pull-right">{$status5}</span>{/if}</a></li>
	<li {if $status == 6}class="active"{/if}><a href="{php echo wl_filter_url('status:6');}">被驳回{if $status6}<span class="label label-warning pull-right">{$status6}</span>{/if}</a></li>
	<li {if $status == 8}class="active"{/if}><a href="{php echo wl_filter_url('status:8');}">回收站{if $status8}<span class="label label-warning pull-right">{$status8}</span>{/if}</a></li>
</ul>
<div class="app-content">
	<div class="app-filter">
		<div class="app-filter">
			<div class="filter-action">
				<a href="{php echo web_url('goodshouse/goodshouse/createactive',array('plugin'=>'fightgroup'))}" class="btn btn-primary">添加商品</a>
			</div>
		</div> 
		<div class="filter-list">
			<form action="" method="get" class="form-horizontal" role="form" id="form1">
				{php echo tpl_form_filter_hidden('wlfightgroup/fightgoods/ptgoodslist');}
				<input type="hidden" name="status" value="{$status}" />
				<div class="form-group form-inline">
					<label class="col-sm-2 control-label">关键字</label>
					<div class="col-sm-9">
						<select name="keywordtype" class="form-control">
							<option value="">关键字类型</option>
							<option value="1" {if $_GPC['keywordtype']==1}selected="selected"{/if}>商品ID</option>
							<option value="3" {if $_GPC['keywordtype']==3}selected="selected"{/if}>商品名称</option>
							{if !is_store()}
							<option value="2" {if $_GPC['keywordtype']==2}selected="selected"{/if}>商家ID</option>
							<option value="4" {if $_GPC['keywordtype']==4}selected="selected"{/if}>商家名称</option>
							{/if}
						</select>
						<input type="text" name="keyword" class="form-control" value="{$_GPC['keyword']}"  placeholder="请输入关键字"/>
                    </div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"></label>
					<div class="col-sm-9">
						<button class="btn btn-primary" id="search">筛选</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="app-table-list">
		<div class="table-responsive">
			<table id="de1" class="table table-hover table-bordered">
				<thead>
				<tr>
					<th class="text-center" width="30px"><input type="checkbox" name="checkall" value="" id="checkall" class="checkboxall" onclick="var ck = this.checked; $(':checkbox').each(function(){this.checked = ck});"/></th>
					<th class="text-center" style="width:40px;">ID</th>
					<th class="text-center" style="width:150px;">商品</th>
					<th class="text-center" style="width:120px;">所属商家</th>
					<th class="text-center" style="width:100px;">价格</th>
					<th class="text-center" style="width:80px;">仓储</th>
					<th class="text-center" style="width:100px;">销量</th>
					<th class="text-center" style="width:60px;">状态</th>
					<th class="text-center" style="width:150px;">操作</th>
				</tr>
				</thead>
				<tbody>
				{loop $list $k $item}
				<tr class="text-center" >
					<td><center><input type="checkbox" name="items[]" value="{$item['id']}" class="checkbox" /></center></td>
					<td>
						<center>{$item['id']}</center>
					</td>
					<!--商品-->
					<td>
						<div class="img" style="text-align: left;padding-left: 2rem;">
							<img style="height: 50px;width: 50px;margin-right: 10px;" class="scrollLoading" src="{IMAGE_PIXEL}" data-url="{php echo tomedia($item['logo'])}">
							<span> {$item['name']}</span>
						</div>
					</td>
					<!--所属商家-->
					<td>
						{$item['storename']}
					</td>
					<!--价格-->
					<td class="text-left">
						<span>团购价：<span class="prstyle">￥{$item['price']}</span></span><br />
						{if $item['aloneprice']}<span>单购价：<span class="prstyle">￥{$item['aloneprice']}</span></span><br />{/if}
						<span>市场价：<span class="prstyle">￥{$item['oldprice']}</span></span><br />
					</td>
					<!--仓储-->
					<td class="text-left">
						<span>库存量：<span class="prstyle">{$item['stock']}</span></span><br />
						<span>成团数：<span class="prstyle">{$item['groupnum']}</span></span><br />
					</td>
					<!--数据-->
					<td>
						<p style="color: #428bca;margin-bottom: 0;"><a href="{php echo web_url('order/wlOrder/checkcodeList',array('plugin'=>'wlfightgroup','status'=>1,'id' => $item['id']))}">已下单：{$item['placeorder']}</a></p>
						<p style="color: #428bca;margin-bottom: 0;"><a href="{php echo web_url('order/wlOrder/checkcodeList',array('plugin'=>'wlfightgroup','status'=>2,'id' => $item['id']))}">已支付：{$item['alreadypay']}</a></p>
						<p style="color: #428bca;margin-bottom: 0;"><a href="{php echo web_url('order/wlOrder/checkcodeList',array('plugin'=>'wlfightgroup','status'=>3,'id' => $item['id']))}">已完成：{$item['alreadyuse']}</a></p>
					</td>
					<!--状态-->
					<td>
						{if $item['status'] == 1}<span class="label label-warning">未开始</span>{/if}
						{if $item['status'] == 2}<span class="label label-success">销售中</span>{/if}
						{if $item['status'] == 3}<span class="label label-danger">已结束</span>{/if}
						{if $item['status'] == 4 ||$item['status'] == 0}<span class="label label-danger">已下架</span> {/if}
						{if $item['status'] == 5}<span class="label label-warning">待审核</span>{/if}
						{if $item['status'] == 6}<span class="label label-danger">被驳回</span>{/if}
						{if $item['status'] == 8}<span class="label label-warning">回收站</span> {/if}
					</td>
					<!--操作-->
					<td style="position: relative;">
						{if p('wxplatform')}
						<a href="javascript:;" data-url="{php echo h5_url('pages/subPages/goods/index',['type'=>3,'id'=>$item['id']])}" class="js-clip">复制链接</a>
						{/if}
						{if p('wxapp')}
						<a href="javascript:;" data-url="pages/subPages/goods/index?type=3&goodsType=3&id={$item['id']}" class="js-clip">复制路径</a>
						{/if}
						<a href="{php echo web_url('goodshouse/goodshouse/createactive',array('plugin'=>'fightgroup','id'=>$item['id'],'page'=>$pindex))}">编辑</a>
						<br />
						<a href="javascript:;" class="js-copy" itemid="{$item['id']}">复制商品</a>
						{if $item['status'] == 8}
						 <a href="{php echo web_url('wlfightgroup/fightgoods/deleteGoods', array('id'=>$item['id']))}"  data-toggle="ajaxRemove" data-confirm="此操作会删除拼团活动，同时导致订单商品数据缺失或其他问题，确定要删除吗？">删除</a>
						{else}
						 <a href="{php echo web_url('wlfightgroup/fightgoods/cutoffGoods', array('id'=>$item['id']))}"  data-toggle="ajaxRemove" data-confirm="确认放入回收站吗？">删除</a>
						{/if}
						{if $item['status'] == 5 && !is_store()}
						<a href="javascript:;" class="pass" itemid="{$item['id']}">通过</a>
						<a href="javascript:;" class="nopass" itemid="{$item['id']}">不通过</a>
						{/if}
						{if ($item['status'] == 1)}
						<p style="color: #428bca;display: inline-block;"><a href="javascript:;" class="js-remove" order-id="{$item['id']}" order-status="{$item['status']}">下架</a></p>
						{/if}
						{if $item['status'] == 4 || $item['status'] == 8}
						<p style="color: #428bca;display: inline-block;"><a href="javascript:;" class="js-remove" order-id="{$item['id']}" order-status="{$item['status']}">上架</a></p>
						{/if}
						{if Customized::init('pft147') > 0}
						<p style="color: #428bca;display: inline-block;"><a href="{php echo web_url('goodshouse/goodshouse/checklist', array('id' => $item['id'],'plugin'=>'wlfightgroup'))}">核销码</a> </p>
						{/if}
					</td>
				</tr>
				{/loop}
				</tbody>
			</table>
		</div>
		<div class="app-table-foot clearfix">
			<div class="pull-left">
				<button class="btn btn-default btn-sm" type="button" onclick="location.reload();"><i class="fa fa-refresh"></i></button>
				<div class="btn-group btn-group-sm">
					<button  class="btn btn-default" disabled="disabled" id="checkYse" onclick="checkOrDelete(1);">批量上架</button>
					<button  class="btn btn-default" disabled="disabled" id="checkNo" onclick="checkOrDelete(4);">批量下架</button>
				</div>
				<button class="btn btn-default btn-sm" type="button" disabled="disabled" id="delete" onclick="checkOrDelete(8);"><i class="fa fa-trash"></i> 回收站</button>
			</div>
			<div class="pull-right">
				{$pager}
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#search").click(function(){
		$('#form1')[0].submit();
	});
</script>
<script>

	function checkOrDelete(check){
		var content = '';
		if(check==1) content = '确认上架选中商品？';
		if(check==4) content = '确认下架选中商品？';
		if(check==8) content = '确认把选中商品放入回收站？如果商品已在回收站将会被彻底删除。';
		layer.open({
			title: [
				'提示',
				'background-color:#23c6c8; color:#fff;'
			]
			,anim: 'up'
			,content: content
			,btn: ['确认', '取消']
			,yes:function(index){
				$('.layer-anim').remove();
				var ids = [];
				var $checks=$('.checkbox:checkbox:checked');
				$checks.each(function() {
					if (this.checked) {
						ids.push(this.value);
					};
				});
				//处理
				$.post("{php echo web_url('wlfightgroup/fightgoods/changestatus')}", { ids : ids ,type:check}, function(data){
					if(!data.errno){
						util.tips("操作成功！");
						location.reload();
					}else{
						util.tips(data.message);
					};
				}, 'json');
			}
		});
	}

	$(function(){
		$('#de1').delegate('.js-remove', 'click', function(e){
			e.stopPropagation();
			var $this = $(this);
			var id = $this.attr('order-id');
			var status = $this.attr('order-status');
			var statushtml = (status != 1 && status != 2) ? "上架" : "下架";
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('wlfightgroup/fightgoods/delete')}", {id:id,status:status}, function(data){
					console.log(data);
					if(!data.errno){
						util.tips(statushtml+"成功！");
						location.reload();
					};
				}, 'json');
			}, {html: '确认'+statushtml+"？"});
		});

		$('.checkbox,.checkboxall').click(function(){
			var $checks=$('.checkbox:checkbox:checked');
			$('#check').attr('disabled','');
			if($checks.length>0) {
				$('#checkYse').attr('disabled',false);
				$('#checkNo').attr('disabled',false);
				$('#delete').attr('disabled',false);
			}else{
				$('#checkYse').attr('disabled',true);
				$('#checkNo').attr('disabled',true);
				$('#delete').attr('disabled',true);
			}
		});
	});
	$('#de1').delegate('.pass','click',function(e){
		e.stopPropagation();
		var id = $(this).attr('itemid');
		util.nailConfirm(this, function(state) {
		if(!state) return;
			$.post("{php echo web_url('wlfightgroup/fightgoods/passGoods')}", { id : id }, function(data){
				if(!data.errno){
				util.tips("审核通过成功！");
				location.reload();
				};
			}, 'json');
		}, {html: '确认通过审核?'});
	});
	$('#de1').delegate('.nopass','click',function(e){
		e.stopPropagation();
		var id = $(this).attr('itemid');
		util.nailConfirm(this, function(state) {
		if(!state) return;
			$.post("{php echo web_url('wlfightgroup/fightgoods/nopassGoods')}", { id : id }, function(data){
				if(!data.errno){
				util.tips("审核不通过成功！");
				location.reload();
				};
			}, 'json');
		}, {html: '确认不通过审核?'});
	});
	
	$('#de1').delegate('.js-copy', 'click', function(e){
		e.stopPropagation();
		var $this = $(this);
		var id = $this.attr('itemid');
		util.nailConfirm(this, function(state) {
			if(!state) return;
			$.post("{php echo web_url('wlfightgroup/fightgoods/copygood')}", {id:id}, function(data){
//				alert(JSON.stringify(data));
				if(!data.errno){
					util.tips("复制成功！");
					location.reload();
				};
			}, 'json');
		}, {html: '确认复制该活动？被复制的商品会在已下架中显示'});
	});
	
	
</script>
{php include wl_template('common/footer');}